﻿using System;
using System.IO;
using System.Net;

namespace MvcWebScraper.Core
{
	public class HttpRequestProvider : IRequestProvider
	{
		public string Load(Uri uri, System.Text.Encoding encoding)
		{
			var request = (HttpWebRequest)WebRequest.Create(uri);

			try
			{
				using (var response = request.GetResponse())
				{
					using (var stream = response.GetResponseStream())
					{
						using (var reader = new StreamReader(stream, encoding))
						{
							return reader.ReadToEnd();
						}
					}
				}
			}
			catch (WebException)
			{
				return string.Empty;
			}
		}
	}
}
